package com.tros.admin.validation;

import java.security.spec.AlgorithmParameterSpec;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

import sun.misc.BASE64Decoder;

public class DecryptValue {
	
	String encry;	
	Cipher cip;
	SecretKeySpec keyValue;
	AlgorithmParameterSpec valSpecAlg ;
    byte[] decryptValue;
    String masterPass = "yogaEswaran12345";
    String retenOutput;  
    boolean value ;
	

	public DecryptValue(String encryPass) {
		// TODO Auto-generated constructor stub
     try{
    	    this.encry = encryPass;
 		    this.cip = Cipher.getInstance("AES/CBC/PKCS5Padding");
 		    this.keyValue = new SecretKeySpec(masterPass.getBytes(), "AES");
 		    this.valSpecAlg = new IvParameterSpec(masterPass.getBytes()); 
 		    
		}catch(Exception e)
		{
			System.out.println("Prob while starting decrypt "+e.getMessage());
		}
		
	}

	public String getDecrptValue() {
		// TODO Auto-generated method stub
		 try
		 {
			 cip.init(Cipher.DECRYPT_MODE, keyValue, valSpecAlg);	
			 this.decryptValue =  new BASE64Decoder().decodeBuffer(encry); 
			 byte[] afterDecrypt = cip.doFinal(decryptValue);
			 this.retenOutput = new String(afterDecrypt);
			 System.out.println("+++++++++ after decrypt ++++++++"+new String(retenOutput));
			 return retenOutput;			 
			 
		 }catch(Exception e)
		 {
			 System.out.println("Prob while sgetting decrypt "+e.getMessage());
		 }
		return retenOutput;
	}

}
